import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    DetailShopper: null,
    cartList: [],
    checked: true //控制是否选中
  },
  mutations: {
    setDetailShopper(state,dataList){
      state.DetailShopper = dataList;
    },
    setCartList(state,list){
      this.getters.getCartList(list);
    },
    setChecked(state,bool){
      state.checked = bool;
    }
  },
  getters: {
    getCartList(state){
      return function(list){
        let number = state.cartList.find((item) => {
          return item.id === list.id;
        });
        if (number !== undefined && number !== ''){
          number.cartCount++;
        }else {
          state.cartList.unshift(list);
        }
      };
    }
  },
  modules: {

  }
});

export default store;
